package com.isdepci.project.reference.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.isdepci.framework.aspectj.lang.annotation.Log;
import com.isdepci.framework.aspectj.lang.enums.BusinessType;
import com.isdepci.project.reference.domain.ReferenceData;
import com.isdepci.project.reference.service.IReferenceDataService;
import com.isdepci.framework.web.controller.BaseController;
import com.isdepci.framework.web.domain.AjaxResult;
import com.isdepci.common.utils.poi.ExcelUtil;
import com.isdepci.framework.web.page.TableDataInfo;

/**
 * 字典数据Controller
 *
 * @author isdepci
 * @date 2023-08-22
 */
@RestController
@RequestMapping("/reference/referenceData")
public class ReferenceDataController extends BaseController
{
    @Autowired
    private IReferenceDataService referenceDataService;

    /**
     * 查询字典数据列表
     */
    @PreAuthorize("@ss.hasPermi('reference:referenceData:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReferenceData referenceData)
    {
        startPage();
        List<ReferenceData> list = referenceDataService.selectReferenceDataList(referenceData);
        return getDataTable(list);
    }

    /**
     * 导出字典数据列表
     */
    @PreAuthorize("@ss.hasPermi('reference:referenceData:export')")
    @Log(title = "字典数据", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ReferenceData referenceData)
    {
        List<ReferenceData> list = referenceDataService.selectReferenceDataList(referenceData);
        ExcelUtil<ReferenceData> util = new ExcelUtil<ReferenceData>(ReferenceData.class);
        return util.exportExcel(list, "referenceData");
    }

    /**
     * 获取字典数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('reference:referenceData:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(referenceDataService.selectReferenceDataById(id));
    }

    /**
     * 新增字典数据
     */
    @PreAuthorize("@ss.hasPermi('reference:referenceData:add')")
    @Log(title = "字典数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReferenceData referenceData)
    {
        return toAjax(referenceDataService.insertReferenceData(referenceData));
    }

    /**
     * 修改字典数据
     */
    @PreAuthorize("@ss.hasPermi('reference:referenceData:edit')")
    @Log(title = "字典数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReferenceData referenceData)
    {
        return toAjax(referenceDataService.updateReferenceData(referenceData));
    }

    /**
     * 删除字典数据
     */
    @PreAuthorize("@ss.hasPermi('reference:referenceData:remove')")
    @Log(title = "字典数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(referenceDataService.deleteReferenceDataByIds(ids));
    }
}
